<docs>
  ## 个人就业登记
</docs>
<template>
  <div class="wrap con-layout" ref="wrap">
    <my-bread title="个人就业登记" :goback="true"></my-bread>
    <co-form :model="data" :rules="rules" ref="form" label="就业信息">
      <p class="tip">{{tipTxt}}</p>
      <co-select prop="jyrylx" label="就业人员类型" v-model="data.jyrylx"
        :list="dontCheck" @send="getName" :tit="true"></co-select>
      <data-picker :label="timeTxt" v-model="data.sysj" ref="kssj"></data-picker>
      <co-select prop="jylx" label="就业类型" v-model="data.jylx"
       :list="codeTable.syry_d_zzjylx"></co-select>
      <select-json label="就业地址" prop="jydd" :checkSelect="checkSelectShow"
        :placeName.sync="data.jyddmc" url="4"
        v-model="data.jydd"></select-json>
      <co-input prop="jyddxxdz" label="详细地址" v-show="lhjyShow" v-model="data.jyddxxdz"></co-input>
      <data-picker prop="jysj" label="就业时间" v-model="data.jysj" ref="jssj"></data-picker>
      <co-input prop="jyfs" label="就业方式" v-show="lhjyShow" v-model="data.jyfs"></co-input>
      <co-input prop="tyshxydm" label="统一社会信用代码" v-show="!lhjyShow" v-model="data.tyshxydm" v-if="tydmShow"></co-input>
      <co-upload :label="uploadTxt" v-show="!lhjyShow" ref="upload" :dateTxt="data.zzyztpCli ? '已上传' : '未上传' "
        :dataName.sync="data.zzyztpCli" :dateImg.sync="data.zzyztpid"></co-upload>
      <co-input prop="zfxysbh" label="转非劳动力自谋职业协议书编号" v-show="zfldlShow" v-model="data.zfxysbh"></co-input>
      <co-input prop="zfxygzh" label="转非劳动力自谋职业协议公证号" v-show="zfldlShow" v-model="data.zfxygzh"></co-input>
       <data-picker prop="zfxysj" label="协议签订时间"  v-show="zfldlShow"
        v-model="data.zfxysj"></data-picker>
      <co-input prop="gyrxm" label="雇佣人或证明人姓名" v-show="lhjyShow" v-model="data.gyrxm"></co-input>
      <co-input prop="gyrsj" label="雇佣人或证明人手机" v-show="lhjyShow" v-model="data.gyrsj"></co-input>
      <tree-select prop="tssf" label="特殊身份" :place="tssfTxt" :items="tssfList" :arrData="tssf" v-if="tssfShow"></tree-select>
      <tree-select prop="fwjg" label="服务机构" :place="fwjgTxt" :items="fwjgList" v-model="data.fwjg" :odd="true"></tree-select>
      <select-json label="就业前在京参保地" prop="cbdxzqh" v-show="cbdShow" ref="cbd"
        :placeName.sync="data.cbdxzqhmc" :url="jsonUrl" :checkSelect="checkSelectShow"
        v-model="data.cbdxzqh"></select-json>
    </co-form>
    <div class="next-step">
      <span class="btn btn-light" @click="PrevStep" v-if='this.slKey != 1'>上一步</span>
      <span class="btn btn-primary" @click="save">提交</span>
    </div>
  </div>
</template>
<script>
import coForm from 'base/form/form';
import coInput from 'base/form/input';
import coSelect from 'base/form/select';
import treeSelect from "base/form/treeSelect";
import treeOdd from "base/form/treeOdd";
import { validator } from 'common/js/valid';
import dataPicker from "base/form/dataPicker3";
import selectJson from "base/form/selectJson";
import coUpload from "base/form/upload/upload";

export default {
  name: 'jyxxDetail',
  components: { coForm, coInput, coSelect, treeSelect, dataPicker, selectJson, coUpload, treeOdd },
  data() {
    return {
      checkSelectShow:true,//显示选择某级级联
      checked:false,
      zfldlShow:false,//转非劳动力显隐
      lhjyShow:false,//灵活就业显隐
      slKey :"",//session 其他业务调转至此页面
      uploadTxt:"营业执照上传",//上传图片显示字段文字
      timeTxt: "前身份终止时间",//判断就业人员类型对应的 时间选项
      tydmShow: true,//统一信用代码  与  转非劳动力显隐  如有数据项显示一个，没有数据想两个都显示，其中一个有值另一个隐藏
      tssfList: [{text:"享受本市居民最低生活保障待遇",id:'01'},{text:"持残疾证人员",id:'02'}],//特殊身份
      fwjgList: [],//特殊身份
      jsonUrl:"",//获取json不同地址
      _dj:"",//跳转页面
      tssf:[],//特殊身份
      tssfTxt:"请选择特殊身份",
      fwjgTxt:"请选择服务机构",
      jbxx:{
        czdxzqh:"", //常住地
        hjxzqh:"", //户籍地
      },//基本信息
      tipTxt:"若您是登记失业人员，服务机构应于失业登记时所选一致，若不一致，系统将自动变更失业登记地为服务机构。",//提示文字
      cbdShow:false,//参保地显示
      tssfShow:false,//特殊身份显隐
      data: {
        jyrylx:'', //就业人员类型
        sysj: '', //前身份终止时间
        jylx: '', //就业类型
        jydd:"",//就业地址  行政区划
        jyddmc:"",//就业地址 名称
        jyddxxdz:'',//就业地详细地址
        jysj:'',//就业时间
        jyfs:'',//就业方式
        tyshxydm:'',//统一社会信用代码
        zfxysbh:'',//转非劳动力自谋职业协议书编号
        zfxygzh:'',//转非劳动力自谋职业协议公证号
        zfxysj:'',//协议签订时间
        gyrxm: '', // 雇佣人或证明人姓名
        gyrsj: '', // 雇佣人或证明人手机
        fwjg: '', // 服务机构
        sfdb:"", //享受本市居民最低生活保障待遇
        sfcj:"",//持残疾证人员
        cbdxzqh:"",//本次失业前在京参保地  行政区划
        cbdxzqhmc:"",//本次失业前在京参保地 名称
        zzyztpCli:"",//本地名称
        zzyztpid:"",//服务器名称
        zjlx:""
      },
      rules: {
        jyrylx: validator("2,less,就业人员类型,false"), // 就业人员类型
        jylx: validator("2,less,就业类型,false"), // 就业类型
        jydd: validator("128,less,就业地址,false"), // 就业地址
        jyddxxdz: validator("64,less,就业地详细地址,true"), // 就业地详细地址
        jysj: validator("10,full,就业时间,false"), // 就业时间
        jyfs: validator("32,full,就业方式,true"), // 就业方式
        tyshxydm: validator("32,zzjgdm,统一社会信用代码,true"), // 统一社会信用代码
        zfxysbh: validator("50,full,转非劳动力自谋职业协议书编号,true"), // 转非劳动力自谋职业协议书编号
        zfxygzh: validator("50,full,转非劳动力自谋职业协议公证号,true"), // 转非劳动力自谋职业协议公证号
        zfxysj: validator("10,full,协议签订时间,true"), // 协议签订时间
        gyrxm: validator("32,full,雇佣人或证明人姓名,true"), // 雇佣人或证明人姓名
        gyrsj: validator("32,full,雇佣人或证明人手机,true"), // 雇佣人或证明人手机
        hjxzqh: validator("128,less,户籍地址,false"), // 户籍地址
        hjdxxdz: validator('128,less,"户籍地详细地址",true'), // 户籍地详细地址
        tssf: validator("4,least,特殊身份,false"), // 特殊身份
        fwjg: validator("1,less,服务机构,false"), // 服务机构
        cbdxzqh: validator("128,less,本次就业前在京参保地,true"), // 本次就业前在京参保地
      },
      dontCheck:[],//不确定数组
      jyrylxList:[],//就业人员类型获取带 id 代码表
      codeTable: {
        syry_d_zzjylx:[], // 就业类型
        syry_d_jyqsf: [], // 就业人员类型
      },
    };
  },
  watch:{
    "jbxx.zjlx":function (val){
      //不同证件类型控制查询不同json文件
      this.jsonUrl = val=='01'?'2':'3';
    },
    // 开始时间，结束时间校验
    'data.sysj':function (val) {
      this.dataFormat(val,'');
    },
    'data.jysj':function (val) {
      this.dataFormat('',val);
    },
    'data.jyrylx': function (val) { //就业人员类型
      if(this.jbxx.hjxz == '20' && val == '07'){
        this.$alert('农业户籍不能选择农转非人员!');
        this.data.jyrylx = '';
        this.timeTxt = '前身份终止时间';
      }
      //转非三项显示
      if(this.data.jylx == '01' && val == '08'){
        this.zfldlShow = true;
        this.uploadTxt = '营业执照或转非协议书上传';
      } else{
        this.zfldlShow = false;
        this.uploadTxt = '营业执照上传';
      }
      // 毕业时间 本年度
      if(this.jbxx.byrq && this.jbxx.byrq.substring(0, 4) !== this.data.xtsj.substring(0, 4) && val == '07'){
        this.$alert('毕业时间不是今年，不能选择 "毕业年度内外地生源高校毕业生" !');
        this.data.jyrylx = '';
      }
    },
    //就业类型 03灵活就业
    "data.jylx": function (val) {
      if(val == '03'){
        this.lhjyShow = true;
        this.data.tyshxydm = '';
        //删除图片
        this.$refs.upload.$refs.uploadPic.imgSrc = '';
        this.data.zzyztpid = '';
        this.data.zzyztpCli = '';
      }else{
        this.lhjyShow = false;
      }
      if(this.data.jyrylx == '08' && val == '01' && this.data.tyshxydm == ''){
        this.zfldlShow = true;
        this.uploadTxt = '营业执照或转非协议书上传';
      } else {
        this.zfldlShow = false;
        this.uploadTxt = '营业执照上传';
      }
    },
    //统一信用代码
    "data.tyshxydm": function (val) {
      if (this.data.jylx == "02") return;
      if(this.data.jyrylx == '08' && this.data.jylx == '01' && val == ''){
        this.zfldlShow = true;
        this.uploadTxt = '营业执照或转非协议书上传';
      } else {
        this.zfldlShow = false;
        this.uploadTxt = '营业执照上传';
      }
    },
     //统一信用代码 与 转非劳动力自谋职业协议书编号 二选一
    "data.zfxysbh": function (val) {
      if (!val) {
        this.tydmShow = true;
      }else{
        this.tydmShow = false;
        this.data.tyshxydm = "";
      }
    },
    //统一信用代码 与 转非劳动力自谋职业协议公证号 二选一
    "data.zfxygzh": function (val) {
      if (!val) {
        this.tydmShow = true;
      }else{
        this.tydmShow = false;
        this.data.tyshxydm = "";
      }},
    //统一信用代码 与 协议签订时间 二选一
    "data.zfxysj": function (val) {
      if (!val) {
        this.tydmShow = true;
      }else{
        this.tydmShow = false;
        this.data.tyshxydm = "";
      }},
    'data.fwjg': function (val) {
      if(val == '3'){
        this.cbdShow = true;
        this.fwjgTxt = '参保地';
      }else{
        this.cbdShow = false;
        this.data.cbdxzqh = this.data.cbdxzqhmc = '';
      }
      if(val == '1'){
        this.fwjgTxt = '户籍地';
      }else if(val == '2'){
        this.fwjgTxt = '常住地';
      }else if(val == '4'){
        this.fwjgTxt = '就业地';
      }
    },
    // 在京参保地
    "data.cbdxzqh": function (val) {
      if (this.jbxx.zjlx == "02") {
        if (val.substring(6, 9) == "000") {
          this.data.cbdxzqh = this.data.cbdxzqhmc = '';
          this.$refs.cbd.$el.childNodes[2].childNodes[0].innerText = '';
          this.$alert("请将本次就业前在京参保地请选择到街道!");
        }
      }else if (this.jbxx.zjlx == "01") {
        if (val.substring(3, 6) == "000") {
          this.data.cbdxzqh = this.data.cbdxzqhmc = '';
          this.$refs.cbd.$el.childNodes[2].childNodes[0].innerText = '';
          this.$alert("请将本次就业前在京参保地请选择到区!");
        }
      }
    },
    //户籍地，居住地判断 特殊身份显隐
    "jbxx.czdxzqh": function (val) {
      const hjddm = this.jbxx.hjxzqh.substr(0, 2); //户籍地
      const czddm = val.substr(0, 2); //常住地
      if(czddm != '11' && hjddm != '11'){
        this.fwjgList=[{text:"参保地",id:'3'},{text:"就业地",id:'4'}];//特殊身份
        window.setTimeout(() => {this.dontCheck = this.syrylxList}, 500);
      }else if(czddm == '11' && hjddm != '11'){
        this.fwjgList= [{text:"常住地",id:'2'}];//特殊身份
        this.cbdShow = false;
        window.setTimeout(() => {this.dontCheck = this.syrylxList}, 500);
      }else if(czddm != '11' && hjddm == '11'){
        this.fwjgList = [{text:"户籍地",id:'1'}];//特殊身份
        window.setTimeout(() => {this.dontCheck = this.syrylxList}, 500);
      }else{//都是北京
        this.fwjgList = [{text:"户籍地",id:'1'},{text:"常住地",id:'2'}];
        window.setTimeout(() => {this.dontCheck = this.codeTable.syry_d_jyqsf}, 500);
      }
      if( hjddm == '11'){
        this.tssfShow = true;
      }else{
        this.tssfShow = false;
        this.data.sfdb =this.data.sfcj = '0';
      }
      if (!this.fwjgList.some( item => item.id == this.data.fwjg)) {
        this.data.fwjg = '';
        this.fwjgTxt = '';
      }
    },
    //特殊身份
    "tssf": function (val) {
      var arr = [];
      var ids = [];
      var id = '';
      this.tssfList.forEach((item)=>{
        val.includes(item.id) ? arr.push(item.text) :'';
        val.includes(item.id) ? ids.push(item.id) :'';
        this.tssfTxt = arr.join(',');
        id = ids.join(',');
      })
      val.filter((i)=>{
        if (i == '01') {
          return this.data.sfdb = "1";
        }else if (i == '02'){
          return this.data.sfcj = "1";
        } else{
          return this.data.sfdb = this.data.sfcj = '0';
        }
      })
    }
  },
  methods: {
    //获取不同时间的显示文字
    getName(val){
      this.timeTxt = val;
    },
    save() {
      this.$refs.form.validate(() => {
        if (this.data.sysj == '') {
          this.$refs.form.errorMsg = `${this.timeTxt}不能为空!`;
          return;
        }
        if (!this.data.zzyztpid && this.data.jylx != '03') {
          this.$refs.form.errorMsg = `${this.uploadTxt}不能为空!`;
          return;
        }
        if (this.lhjyShow && !this.data.jyddxxdz) {
          this.$refs.form.errorMsg = `详细地址不能为空!`;
          return;
        }
        if (this.lhjyShow && !this.data.jyfs) {
          this.$refs.form.errorMsg = `就业方式不能为空!`;
          return;
        }
        if (this.lhjyShow && !this.data.gyrxm) {
          this.$refs.form.errorMsg = `雇佣人或证明人姓名不能为空!`;
          return;
        }
        if (this.lhjyShow && !this.data.gyrsj) {
          this.$refs.form.errorMsg = `雇佣人或证明人手机不能为空!`;
          return;
        }
        if(this.data.jylx == '01' && this.data.jyrylx == '08'){
          if (this.data.tyshxydm == ''&& (this.data.zfxysbh == '' || this.data.zfxygzh == '' || this.data.zfxysj == '')) {
            this.$refs.form.errorMsg = `统一社会信用代码或转非劳动力自谋职业协议书编号不能为空不能为空!`;
            return;
          }
        }
        if (!this.lhjyShow  && !this.data.tyshxydm) {
          this.$refs.form.errorMsg = `统一社会信用代码不能为空!`;
          return;
        }
        // const czdxzqh = this.jbxx.czdxzqh.substr(0, 2);
        // const hjxzqh = this.jbxx.hjxzqh.substr(0, 2);
        if(!this.data.fwjg){
          this.$refs.form.errorMsg = '服务机构不能为空!';
          return;
        }
        // if ((czdxzqh != '11' || czdxzqh == '11')&& hjxzqh != '11' ) {
        //   if(!this.data.fwjg){
        //     this.$refs.form.errorMsg = '服务机构不能为空!';
        //     return;
        //   }
        // }
        // if ( czdxzqh == '11' && hjxzqh == '11' ) {
        //   if(this.data.fwjg != '1' && this.data.fwjg != '2' ){
        //     this.$refs.form.errorMsg = '服务机构不能为空!';
        //     return;
        //   }
        // }
        if (this.cbdShow && !this.data.cbdxzqh ) {
          this.$refs.form.errorMsg = '就业前在京参保地不能为空!';
          return;
        }
        this.data.syrqmc = this.timeTxt;
        this.data.sjly = "3";//微信端保存必填
        this.$confirm('本人承诺上述信息真实有效', '提示',{check:true})
        .then(()=>{
          //保存后台校验两个字段，为03灵活就业，删除两个字段
          if (this.data.jylx == '03') {
            delete this.data.zzyztpid;
            delete this.data.zzyztpCli;
          }
          this.POST_save();
        })
        .catch();
      });
    },
    //上一步
    PrevStep(){
      this.$loading = true;
      this.$http
        .post("/jysydj/jyxxZc", this.data)
        .then(res => {
          const code = +res.returnData.executeResult;
          if (code === 1) {
            this.$router.go(-1);
            // this.$router.push({ path: "/baseData", query:{dj:'2'} });
          }
        })
        .finally(() => {
          this.$loading = false;
        });
    },
    /* 获取代码表 */
    GET_codeTable() {
      const arrTableName = Object.keys(this.codeTable);
      this.$http.get('/jysydj/CodeOperation/getCodeData', {
        params: {
          dmbm: arrTableName.join()
        }
      }).then((res) => {
        const data = res.returnData;
        arrTableName.forEach(item => {
          this.codeTable[item] = data[item];
        });
      });
    },
    /* 保存信息修改 */
    POST_save() {
      this.$loading = true;
      this.$http
        .post("/jysydj/jyxxBc", this.data)
        .then(res => {
          const code = +res.returnData.executeResult;
          if (code === 1) {
            this.$alert({
              message: res.returnMsg || '操作成功!',
              cb:()=>{
                if (this.slKey === '1') {
                  this.slKey = null;
                  window.location.href = "/jycy/webapp/sybxjsl/weixin/index.html";//线上
                  // window.location.href = "/bksxrjcsbb_ywd/sybxjsl/weixin/index.html";//测试
                } else {
                  this.$router.push({path:"/index"});
                }
              }
            });
          }else{
            this.$alert(res.returnMsg)
          }
        })
        .finally(() => {
          this.$loading = false;
        });
    },
    /* 获取代码表 失业人员类型获取带 id 代码表*/
    GET_dab(id){
      this.$http.get('/jysydj/CodeOperation/getCodeData', {
        params: {
          dmbm: 'syry_d_jyqsf',
          xzqhdm: id
        }
      }).then((res) => {
        const data = res.returnData;
        this.syrylxList = data.syry_d_jyqsf;
      });
    },
    /*  查询基本信息 */
    GET_getInfo() {
      this.$loading = true;
      this.$http.get('/jysydj/jyxxCx').then(res => {
        const resData = res.returnData;
        this.jbxx = resData.jbxx;
        Object.keys(this.data).forEach(item => {
          this.data[item] = resData.jyxx[item];
        });
        this.GET_dab(this.jbxx.hjxzqh);
        this.tssf.push(this.data.sfdb == '1'?'01':'');//保障待遇
        this.tssf.push(this.data.sfcj == '1'?'02':'');//残疾
        this.sbkSwich = this.data.shbzkh ? 1 : 0;
        //值为1，港澳台人员社会保障卡号和出生 日期和性别不能改。
        if (this.data.zjlx == '02' && this.data.wwsfbl == '1') this.bzkh = true;
      }).finally(() => {
        this.$loading = false;
      });
    },
    dataFormat(star,end) {
      const minday = this.data.sysj;
      const maxday = this.data.jysj;
      if (minday && maxday) {
        const minArr = minday.split('-');
        const maxArr = maxday.split('-');
        var dataStartTime = new Date(minArr[0],minArr[1]-1,minArr[2]);
        var dataEndTime = new Date(maxArr[0],maxArr[1]-1,maxArr[2]);
        if (star) {
          if(dataStartTime > dataEndTime){
            this.$alert(`${this.timeTxt}不能大于就业时间!`);
            this.$refs.kssj.$el.children[1].innerText = '';
            this.data.sysj = '';
          }else{
            this.$refs.kssj.$el.children[1].innerText = star;
          }
        }else{
          if(dataStartTime > dataEndTime){
            this.$alert(`就业时间不能小于${this.timeTxt}!`);
            this.$refs.jssj.$el.children[1].innerText = '';
            this.data.jysj = '';
          }else{
            this.$refs.jssj.$el.children[1].innerText = end;
          }
        }
      }
    }
  },
  created() {
    // 获取代码表
    this.GET_codeTable();
    this.GET_getInfo();
    this._dj = this.$route.query.dj;
    this.slKey = window.location.search.split('=')[1]; //申领标识
  }
};
</script>
<style scoped lang="scss">
@import '~common/scss/var.scss';
.wrap {
  background: $color-bg;
  overflow: auto;
  .tape{
    margin-top: 20px;
  }
  .weui-cell{
    background-color: #fff;
  }

  .next-step {
    margin: 42px 0 20px 0;
    padding: 0 34px;
    .btn{
      width: 330px;
    }
    .btn-primary{
      margin-left:10px;
    }
  }
}
.switch{
  font-size: 26px;
}
.tip{
  padding: 10px 30px;
  color: #ff9933;
  font-size: 26px;
}
</style>
